var loadPageStatus = [];
var questionSaveStatus = {};
/**
 * 加载试题数据列表
 * @param obj
 */
function loadTaskQuestionList(obj) {
    if(loadPageStatus.indexOf(obj.pageNo) ==-1){
        loadPageStatus.push(obj.pageNo);
        $.ajax({
            url:baseloaction +'/web/uc/task/loadTaskQuestionList',
            type:'post',
            dataType:'html',
            data:{
                'examRecordId':obj.examRecordId,
                'status':obj.status,
                'currentPage':obj.pageNo
            },
            success:function (html) {
                if(obj.pageNo==1){
                    $("#carousel-professional>.carousel-inner").append(html);
                }else {
                    var pageEm = $("#carousel-professional article[data-no="+obj.pageNo+"]")[0];
                    $(html).insertBefore($(pageEm));
                    //删除临时点位的元素
                    $("#carousel-professional .temporary-box[data-no="+obj.pageNo+"]").remove();
                }

                //初始化单多选控件
                rcFromFn();
                //判断回调方法
                if($.isFunction(obj.callback)){
                    obj.callback();
                }
            },
            error:function (error) {
                icModale(0,'','系统错误试题加载失败');
            }
        });
    }
}

/**
 * 加载作业答题卡数据
 * @param examRecordId 考试记录ID
 */
function loadTaskCard(examRecordId) {
    setTimeout(function () {
        $.ajax({
            url: baseloaction +'/web/uc/task/loadTaskCard',
            type:'post',
            dataType:'html',
            data:{
                'examRecordId':examRecordId
            },
            success:function (html) {
                $("#task-card-list-box").html(html);
                var cardList = $("#task-card-list-box li>a");
                $.each(cardList,function (index,em) {
                    var id = $(em).data('id');
                    questionSaveStatus['qr'+id]={'id':id,'status':false};
                });
                //初始化试题滑动插件
                $('.sidebar-collapse').slimScroll({
                    height: '100%',//可滚动区域高度
                    railOpacity: 0.9,//轨道透明度
                    alwaysVisible: false,//是否 始终显示组件
                    distance: '-30px',//组件与侧边之间的距离
                    railDraggable:true,//是否 滚动条可拖动
                    disableFadeOut:true,//是否 鼠标经过可滚动区域时显示组件，离开时隐藏组件
                    size:'10px'//滚动条宽度，即组件宽度
                });
            },
            error:function (error) {
                icModale(0,'','系统错误加载作业答题失败');
            }
        });
    },300);
}

/**
 * 初始化单多选控件
 */
function rcFromFn() {
    $('.i-checks').iCheck({
        checkboxClass: 'icheckbox_square-green',
        radioClass: 'iradio_square-green'
    });
}

/**
 * 更新保存后的数据
 * @param saveId
 * @param currentId
 */
function updateSaveData(saveId,currentId,callback) {
    if(currentId > 0){
        questionSaveStatus['qr'+currentId] = {'id':currentId,'status':true};
    }
    if(saveId > 0){
        questionSaveStatus['qr'+saveId] = {'id':saveId,'status':false};
    }
    if($.isFunction(callback)){
        callback();
    }
}

/**
 * 获取要保存的试题记录ID
 * @param currentId
 * @returns {number}
 */
function getSaveId(currentId) {
    var status = true;
    var saveId = 0;
    $.each(questionSaveStatus,function (index,obj) {
        if(obj.status==true && status==true && obj.id != currentId){
            saveId = obj.id;
            status = false;
        }
    });
    return saveId;
}
